package net.chenlin.dp.modules.utils;

import net.chenlin.dp.modules.newBusiness.entity.vo.TopologyNodeTreeVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Yansgm
 * @Description:
 * @Date: 2025-04-27 15:22:33
 */
public class TreeUtils {

    // 根据节点获取下面的所有子节点的主键id
    public static List<TopologyNodeTreeVo> getChildIds(TopologyNodeTreeVo node) {
        List<TopologyNodeTreeVo> ids = new ArrayList<>();
        getChildIdsHelper(node, ids);
        return ids;
    }

    private static void getChildIdsHelper(TopologyNodeTreeVo node, List<TopologyNodeTreeVo> ids) {
        if (node == null) {
            return;
        }
        ids.add(node); // 添加当前节点的ID
        for (TopologyNodeTreeVo child : node.getChild()) {
            getChildIdsHelper(child, ids); // 递归处理每个子节点
        }
    }
}
